﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace BlackJack1
{
    internal class Player
    {
        private int index; //牌的下标索引
        private int sum; //目前所持有点数
        private bool isContinue;//是否继续要牌
        private bool hasAce = false;//是否有jack(A)
        private List<Card> pockers = new List<Card>();//当前持有牌组

        public int Index { set { index = value; } get { return index; } }
        public int Sum { set { sum = value; } get { return sum; } }
        public bool IsContinue { set { isContinue = value; } get { return isContinue; } }
        public bool HasAce
        { 
            get { 
                for(int i = 0; i < pockers.Count; i++)
                {
                    if (pockers[i] != null && pockers[i].Num == 1)
                    {
                        hasAce = true;
                    }
                }
                return hasAce; } 
        }
        public List<Card> Pockers { set { pockers = value; } get { return pockers; } }
        public Player() { }

        public int CalTotal()
        {
            int total = 0;
            foreach(Card card in pockers)
            {
                if (card.Num == 1) hasAce = true;
                total += card.Num <= 10 ? card.Num : 10;
            }

            return total > 21 ? 0 : total;
        }

        public virtual void TakeCard(Pocker p)
        {
            pockers.Add(p.Draw());
            isContinue = true;
            if(CalTotal() == 0) 
            {
                isContinue = false;
                sum = 0;
            }
        }

        public void IsHasAce()
        {
            if (hasAce)
            {
                Console.WriteLine("是否要将A变成点数11? y/n");
                string input = Console.ReadLine();
                if (input == "y")
                {
                    sum += 11;
                }
            }
        }

        public void PrintPockers()
        {
            Console.WriteLine("玩家初始化后手中的牌: " + string.Join(", ", Pockers));

        }
    }
}
